<?php



class mod_emailmarketing extends CI_Model {



    function __construct() {

        parent::__construct();

    }



	function count_emailsettings() 

	{

		return $this->db->count_all_results('email_templates');

	}

   /**

	 * Get Email settings from database

	 *

	 * @access	private

	 * @param	nil

	 * @return	array	payment settings informations in array format

	 */

	 function getEmailSettings_with_count($limit=false, $start='', $perpage='',$conditions=array())

	 {

	 	if(count($conditions)>0)		

	 		$this->db->where($conditions);

	  

	  	$this->db->limit($perpage,$start);

	  	$this->db->from('email_templates');

		$this->db->select('email_templates.id,email_templates.type,email_templates.title,email_templates.start_date,email_templates.end_date,email_templates.mail_subject,email_templates.mail_body,email_templates.status');

		$result = $this->db->get();

		return $result;

			

	 }//End of getEmailSettings Function

	 

	 function getEmailSettings($conditions=array())

	 {

	 	if(count($conditions)>0)		

	 		$this->db->where($conditions);

	  

	  	$this->db->from('email_templates');

		$this->db->select('email_templates.id,email_templates.type,email_templates.title,email_templates.start_date,email_templates.end_date,email_templates.mail_subject,email_templates.mail_body,email_templates.status');

		$result = $this->db->get();

		return $result;

			

	 }//End of getEmailSettings Function

	 

	 	

	/**

	 * Add Email Settings

	 *

	 * @access	private

	 * @param	array	an associative array of insert values

	 * @return	void

	 */

	 function addEmailSettings($insertData=array())

	 {

	 	$this->db->insert('email_templates', $insertData);

		return; 

	 }//End of getGroups Function

	 // --------------------------------------------------------------------

	 

	 /**

	 * delete Email Settings

	 *

	 * @access	private

	 * @param	array	an associative array of insert values

	 * @return	void

	 */

	 function deleteEmailSettings($condition=array())

	 {

	    if(isset($condition) and count($condition) > 0)

			$this->db->where($condition);

		

	 	$this->db->delete('email_templates');

		return; 

	 }//End of getGroups Function

	 //------------------------------------------------------------------------

	 

	 /**

	 * Send Mail

	 *

	 * @access	private

	 * @param	array

	 * @return	array	site settings informations in array format

	 */

	function sendMail($to ='',$from ='',$subject='',$message='',$cc='')

	{

		//echo $from;exit;

		// load Email Library 

		$config = Array(

	    'protocol' => 'smtp',

	    'smtp_host' => 'smtp.mailgun.org',

	    'smtp_port' => 587,

	    'smtp_crypto' => 'sslv2',

	    'smtp_user' => 'postmaster@3dcrossingmobeen.mailgun.org',

	    'smtp_pass' => '48qr3xq2thk3',

	    'mailtype'  => 'html', 

	    'charset'   => 'iso-8859-1'

		); 

		$this->load->library('email',$config);

		

		$config['mailtype'] = 'html';

		$config['wordwrap'] = TRUE;

		
		
		$this->email->initialize($config);



		$this->email->to($to);

    		$this->email->from($from);

		$this->email->cc($cc);
		$this->email->set_mailtype('html');
   		$this->email->subject($subject);

    		$this->email->message($message);

		if ( ! $this->email->send()){

		echo $this->email->print_debugger();

		}

		

	} // Function sendmail End

	

	/**

	 * Update Email Settings

	 *

	 * @access	private

	 * @param	array	an associative array of insert values

	 * @return	void

	 */

	 function updateEmailSettings($id=0,$updateData=array())

	 {

	 	$this->db->where('id', $id);

	 	$this->db->update('email_templates', $updateData);
		
		 

	 }//End of editGroup Function 

	 

	 function sendHtmlMail($to ='',$from ='',$subject='',$message='',$cc='')

	{

		// load Email Library 

		$this->load->library('email');

		

		$config['mailtype'] = 'html';

		$config['wordwrap'] = TRUE;

		

		$this->email->initialize($config);



		$this->email->to($to);

    		$this->email->from($from);

		$this->email->cc($cc);

   		$this->email->subject($subject);

    		$this->email->message($message);

		if ( ! $this->email->send())

                          {

		echo $this->email->print_debugger();

		}		

	} 



	 

}

// End mod_newsletter Class

   

/* End of file Email_model.php */ 

/* Location: ./app/models/Email_model.php */

